package com.vtb.base;

import com.vtb.utils.DateUtils;
import com.vtb.utils.MailUtils;

@SuppressWarnings("serial")
public class VtbException extends RuntimeException {

    private static int i = 0;
    public VtbException(Throwable cause) {
        super(cause);
    }

    public VtbException() {
        super();
    }

    public VtbException(String message, Throwable cause) {
        super(message, cause);
        try {
            StringBuilder exception = new StringBuilder();
            exception.append("发生异常的类："+cause+"\n"+"发生时间"+DateUtils.getDateString()+"\n"+"异常详细信息：");
            StackTraceElement[] messages = cause.getStackTrace();
            int length = messages.length;
            for (int i = 0; i < length; i++) {
                exception.append("\n").append(
                        messages[i].toString());
            }
            i++;
            //DataCache.mailQeque.put("截止到:"+DateUtils.getDateString()+"为止,微同步已发生"+i+"次异常");
            if (i%50 == 0) {
                MailUtils.sendMail("截止到:"+DateUtils.getDateString()+"为止,微同步已发生"+i+"次异常");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public VtbException(String message) {
        super(message);
        i++;
        if (i%50 == 0) {
            MailUtils.sendMail("截止到:"+DateUtils.getDateString()+"为止,微同步已发生"+i+"次异常");
        }
        /*try {
            DataCache.mailQeque.put("截止到:"+DateUtils.getDateString()+"为止,微同步已发生"+i+"次异常");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
    }

}
